﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MaterialEdit.aspx.cs" Inherits="HQWeb.SysManage.MaterialManage.MaterialEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <base target="_self" />
    <link href="../../Styles/GridViewStyle.css" rel="Stylesheet" type="text/css" />
    <link href="../../Styles/Site.css" rel="Stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/jquery-1.7.2.js"></script>
    <script type="text/javascript">
        function ShowImage(obj) {
            var allowSuffix = ".jpg,.bmp,.gif,.png";  //.jpg,.bmp,.gif,.png,允许上传文件的后缀名
            var suffix = obj.value.substring(obj.value.lastIndexOf(".") + 1).toLowerCase();
            var browserVersion = window.navigator.userAgent.toUpperCase(); //浏览器版本信息           

            if (allowSuffix.indexOf(suffix) > -1) {
                if (window.navigator.appName == "Microsoft Internet Explorer") {//ie浏览器
                    if (browserVersion.indexOf("MSIE 6.0") > -1) {//ie6
                        $("#imgHeadPhoto").attr("src", obj.value);
                    } else {//ie7、ie8、ie9未测试
                        //if(browserVersion.indexOf("MSIE 7.0")>-1 || browserVersion.indexOf("MSIE 8.0")>-1 ||browserVersion.indexOf("MSIE 9.0")>-1)
                        //滤镜实现
                        obj.select();
                        var newPreview = document.getElementById("divNewPreview");
                        if (newPreview == null) {
                            newPreview = document.createElement("div");
                            newPreview.setAttribute("id", "divNewPreview");
                            newPreview.style.width = 100;
                            newPreview.style.height = 100;
                            newPreview.style.border = "solid 1px #d2e2e2";
                        }
                        newPreview.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='" + document.selection.createRange().text + "')";
                        $("#divPreview").attr("style", "display:none");
                        $("#divPreview").after(newPreview);
                    }
                } else if (browserVersion.indexOf("FIREFOX") > -1) { //火狐浏览器
                    var firefoxVersion = parseFloat(window.navigator.userAgent.toLowerCase().match(/firefox\/([\d.]+)/)[1]);
                    if (firefoxVersion < 7) {//firefox7.0以下版本
                        $("#imgHeadPhoto").attr("src", obj.files[0].getAsDataURL());
                    } else {//火狐7.0以上版本
                        $("#imgHeadPhoto").attr("src", window.URL.createObjectURL(obj.files[0]));
                    }
                } else if (obj.files) {
                    //兼容chrome等，也可以兼容火狐，通过HTML5来获取路径                   
                    if (typeof FileReader !== "undefined") {
                        var reader = new FileReader();
                        reader.onload = function (e) { $("#imgHeadPhoto").attr("src", e.target.result); }
                        reader.readAsDataURL(obj.files[0]);
                    } else if ($.browser.safari) {
                        alert("暂时不支持Safari浏览器!");
                    }
                } else {
                    $("#imgHeadPhoto").attr("src", obj.value); //其他
                }
            } else {
                alert("仅支持" + allowSuffix + "为后缀名的文件!");
                //清空选中文件           
                obj.value = "";
                if (window.navigator.appName == "Microsoft Internet Explorer") {
                    obj.select();
                    document.selection.clear();
                    //obj.createTextRange().execCommand("delete");
                }
                obj.outerHTML = obj.outerHTML;
            }
        }
    </script>
    <script type="text/javascript" language="javascript">
        function CheckData() {
            var varNmae = document.getElementById("txtName");
            if (varNmae.value.replace(/(\s*$)/g, "") == "") {
                alert("元素名不能为空！");
                varNmae.focus();
                return false;
            }
            return true;
        }

        function MaterialSelect() {
            var str = window.showModalDialog("../../Resources/MaterialTreeFrame.htm", " ", "dialogWidth=400px;dialogHeight=600px");
            if (str != undefined) {
                document.getElementById("ddl_enty").value = str.id;
            }
        }


        function getImgSrc() {
            //得到上传控件
            file = document.getElementById('fileUp');

            // 把上传控件的value赋值给img控件
            document.getElementById('imgUp').src = file.value;
        }
        function gouBack() {
           window.opener.document.getElementById("bnSearch").click();
            window.close();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table width="98%">
            <tr>
                <td colspan="4" class="title">
                    <asp:Label runat="server" ID="labTitle" Text="元素材料信息"></asp:Label>
                </td>
            </tr>
            <tr>
                <td align="right" style="width: 20%">
                    元素名称：
                </td>
                <td style="width: 30%">
                    <asp:TextBox runat="server" ID="txtName" Style="margin-bottom: 0px"></asp:TextBox><span
                        style="color: Red">*</span>
                </td>
                <td align="right" style="width: 20%">
                    价 格：
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtprice"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="right" style="width: 20%">
                    颜色：
                </td>
                <td>
                    <asp:DropDownList ID="ddl_color" runat="server" Width="156px">
                    </asp:DropDownList>
                </td>
                <td align="right" style="width: 20%">
                    计量单位：
                </td>
                <td>
                    <asp:DropDownList ID="ddl_unit" runat="server" Width="156px">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td align="right" style="width: 20%">
                    元素类型：
                </td>
                <td>
                    <asp:DropDownList ID="ddl_enty" runat="server" Width="156px">
                    </asp:DropDownList>
                    &nbsp;&nbsp;<input type="button" value="选 择" id="materialSelect" onclick="MaterialSelect()" />
                </td>
                <td align="right" style="width: 20%">
                    规格：
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtspecifications"></asp:TextBox>
                </td>
            </tr>
            <tr style="width: 100px">
                <td align="right" style="width: 20%">
                    备 注：
                </td>
                <td>
                    <asp:TextBox TextMode="MultiLine" runat="server" ID="txtremark" Width="250px"></asp:TextBox>
                </td>
                <td align="right" style="width: 20%">
                    图片预览：
                </td>
                <td>
                    <div id="divPreview">
                        <img id="imgHeadPhoto" runat="server" alt="" src="../../Images/Element/nophoto.bmp"
                            style="width: 100px; height: 100px; border: solid 1px #d2e2e2;" />
                    </div>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td colspan="3">
                    &nbsp;&nbsp;&nbsp; &nbsp;<asp:Button ID="btnSubmit" runat="server" Text="添 加" CommandName="add"
                        OnClick="btnSubmit_Click" OnClientClick="return CheckData()" />&nbsp; &nbsp;
                    <input id="btnCalcel" onclick="location='MaterialList.aspx?pid=<%=Request["type_id"] %>'"
                        type="button" value="返 回" />
                    &nbsp;&nbsp;
                    <input id="fuHeadPhoto" runat="server" name="filePhoto" onchange="ShowImage(this)"
                        size="20" type="file" />
                    &nbsp;&nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="4" align="center">
                    <br />
                    <br />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
